package com.feeyo.groundservice.base_util

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.ContextCompat
import com.blankj.utilcode.util.Utils

/**
 *作者：70893 on 2025-09-17
 *描述：资源类型的
 */

/**根据文件名称获取id**/
fun String.getDrawableId(context: Context) = context.resources.getIdentifier(
    this, "drawable", context.packageName
)

/**根据资源ID获取文本**/
fun Int.getString() = Utils.getApp().resources.getString(this)

fun Int.getString(vararg params: Any) = Utils.getApp().resources.getString(this, *params)

/**获取尺寸dp->px**/
fun Int.getPxFromResource() = Utils.getApp().resources.getDimensionPixelSize(this)

fun Int.toDrawable() = Utils.getApp().resources.getDrawable(this, null)

/**解析颜色**/
fun Int.getColor() = ContextCompat.getColor(Utils.getApp(), this)

fun String.getColor(defaultColor: Int = Color.BLACK) =
    if (this.isEmpty()) defaultColor else Color.parseColor(this)

fun Int.getColorList() = AppCompatResources.getColorStateList(Utils.getApp(), this)
